<?php
include("include/config.inc.php");
if(isset($_POST['notOkData']) && $_POST['notOkData'] ==1)
{
	$selNotOkData = "SELECT * FROM planning WHERE planningId = (SELECT parentPlanningId FROM planning WHERE planningId =".$_POST['planningId'].")";
	$selNotOkDataRes = mysql_query($selNotOkData);
	$notOkArray = array();
	$b = 0;
	if(mysql_num_rows($selNotOkDataRes) > 0)
	{
		while($notOkRow = mysql_fetch_array($selNotOkDataRes))
		{
			if($notOkRow['temp1'] != 0)
			{
			  $notOkArray[$b]['temp']    = $notOkRow['temp1'];
			  $notOkArray[$b]['soaking'] = $notOkRow['soaking1'];
			  $notOkArray[$b]['furnace'] = $notOkRow['fId1'];
			  $b++;
			}
			if($notOkRow['temp2'] != 0)
			{
				$notOkArray[$b]['temp'] = $notOkRow['temp2'];
				$notOkArray[$b]['soaking'] = $notOkRow['soaking2'];
				$notOkArray[$b]['furnace'] = $notOkRow['fId2'];
			  $b++;
			}
			if($notOkRow['temp3'] != 0)
			{
				$notOkArray[$b]['temp'] = $notOkRow['temp3'];
				$notOkArray[$b]['soaking'] = $notOkRow['soaking3'];
	  		$notOkArray[$b]['furnace'] = $notOkRow['fId3'];
			  $b++;
			}
		}
	}
	$smarty->assign("b",$b);
	$smarty->assign("notOkArray",$notOkArray);
	$smarty->display('notOkPlanningAj.tpl');
}
elseif(isset($_POST['planningId']))
{
	$selectProcess = "SELECT incomingId, partyId, quantity, weight, processId1, processId2, processId3, temp1, soaking1, fId1, temp2, soaking2, fId2, temp3, soaking3, fId3
	                    FROM planning
	                   WHERE planningId = ".$_POST['planningId'];
  $selectProcessRes = mysql_query($selectProcess);
  $processArray = array();
  $a = 0;
  if($processRow = mysql_fetch_array($selectProcessRes))
  {
  	$processArray[$a]['processId1'] = $processRow['processId1'];
  	$processArray[$a]['processId2'] = $processRow['processId2'];
  	$processArray[$a]['processId3'] = $processRow['processId3'];
  	
  	$processArray[$a]['process1'] = 0;
  	$processArray[$a]['process2'] = 0;
  	$processArray[$a]['process3'] = 0;
  	
  	if($processRow['temp1'] != 0)
  	{
  	  $processArray[$a]['temp1']    = $processRow['temp1'];
  	  $processArray[$a]['soaking1'] = $processRow['soaking1'];
  	  $processArray[$a]['furnace1'] = $processRow['fId1'];
  	  $processArray[$a]['process1'] = 1;
  	}
  	if($processRow['temp2'] != 0)
  	{
  	  $processArray[$a]['temp2']    = $processRow['temp2'];
  	  $processArray[$a]['soaking2'] = $processRow['soaking2'];
  	  $processArray[$a]['furnace2'] = $processRow['fId2'];
  	  $processArray[$a]['process2'] = 1;
  	}
  	if($processRow['temp3'] != 0)
  	{
    	$processArray[$a]['temp3']    = $processRow['temp3'];
    	$processArray[$a]['soaking3'] = $processRow['soaking3'];
  	  $processArray[$a]['furnace3'] = $processRow['fId3'];
  	  $processArray[$a]['process3'] = 1;
  	}
  	$processArray[$a]['incomingId'] = $processRow['incomingId'];
  	$processArray[$a]['partyId']    = $processRow['partyId'];
  	$processArray[$a]['quantity']   = $processRow['quantity'];
  	$processArray[$a]['weight']     = $processRow['weight'];
  	
    $a++;
  }
echo Json_Encode($processArray);  
}
?>